<extend name="Public/base"/>
<block name="content">
    <form class="layui-form layui-form-pane1" action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
                <input type="text" name="goods_title" lay-verify="required|title" required placeholder="请输入标题"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品分类</label>
            <div class="layui-input-inline" id="sel">
                <select name="goods_sort" lay-filter="aihao" lay-search>
                    <option value=""></option>
                    <volist name="res" id="vo">
                    <option value="{$vo.id}">{$vo.title}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品图片</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="upload" >图片上传</button>
                <div class="layui-upload-list" id="thumbnail"></div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商品描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="goods_desc"></textarea>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">价格</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="number" name="goods_price" placeholder="￥" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 10px">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</block>

<block name="js">
    <script src="__PUBLIC__/layui/layui.js"></script>
    <script>
        layui.use('upload', function(){
            var $ = layui.jquery,
                upload = layui.upload;

            upload.render({
                elem: '#upload',
                url: "{:U('Goods/file')}",
                multiple: true,
                before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#thumbnail').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                    });
                },
                done: function(res){
                    //上传完毕
                    $('#thumbnail').append('<input type="hidden" name="goods_pic" value="'+res.data.fileName +'" />')
                }
            });

        });
    </script>
</block>
